/**
* @author Meng Zhang
**/

#define __MAX_ACCELERATOR_STEP 5
#pragma once

struct KeyToCommand {
	int step;//handle two-step Accelerator
	int modifier[__MAX_ACCELERATOR_STEP];
	int key[__MAX_ACCELERATOR_STEP];
	UINT msg;
};

class Accelerator {
	typedef std::vector<KeyToCommand> Container;
public:
	void Initialize();
	
	BOOL RegisterKey(UINT msg , int* modifier, int *key, int step = 1);
	void Clear();
	
	BOOL HandleMsg(MSG *pMsg);

	Container::iterator FindMsg(UINT msg);

	static int GetMaxStep();
	const KeyToCommand& State() const { return state; }
private:
	Container kmap;
	KeyToCommand state;

	//return 0 if failure
	UINT GetAccel(int key, int modifier);

	//return 0 if failure return -1 if got some prefix
	UINT FindAccel(const KeyToCommand& cmd);
};

struct StringToCmd {
	char* sName;
	UINT uCmd;
};


BOOL LoadAccelConfig(char* filepath, Accelerator* accel, StringToCmd strCmd[]);
BOOL LoadAccelConfig(char* filepath, Accelerator* accel, char* str , UINT cmd);
void UpdateStatusBar(Accelerator* accel, CStatusBar* bar);

